package com.tungse.study.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Tungse
 */
public class PoolMain {

    public static void main(String[] args) {
//        new ThreadPoolExecutor();
//        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor


//        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor();
//        threadPoolExecutor.execute();

        MyThreadPool myThreadPool = new MyThreadPool(2, 4,
                1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5), new DiscardRejectHandle());

        for (int i = 0; i < 8; i++) {
            final int fi = i;
            myThreadPool.execute(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + "开始执行任务" + fi);
                    Thread.sleep(2000);
                    System.out.println(Thread.currentThread().getName()  + "执行完成" + fi);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            });
        }

        System.out.println("主线程正常运行");
    }
}
